/**
 * 
 */
package fr.cephb.joperon.core.db;

import java.util.ArrayList;
import java.util.List;

import com.sleepycat.db.DatabaseException;

import fr.cephb.joperon.core.Fid;
import fr.cephb.joperon.core.Operon;
import fr.cephb.joperon.core.bio.Assembly;
import fr.cephb.joperon.core.db.base.BaseSnpIdsDB;
import fr.cephb.joperon.core.entities.SnpIds;
import fr.cephb.util.Pair;

/**
 * @author lindenb
 *
 */
public class SnpIdsDB
	extends BaseSnpIdsDB
	{
	/**
	 * @param operon
	 */
	public SnpIdsDB(Operon operon,Assembly assembly) {
		super(operon,assembly);
	}

	public SnpIdsDB(Operon operon) {
		super(operon);
	}
	
	public List<Fid> getFids(String key) throws DatabaseException
		{
		 List<Fid> v= new ArrayList<Fid>();
		 for(SnpIds snpid:get(key)) v.add(snpid.getFid());
		 return v;
		}
	
	
	
	
	/**
	 * 
	 * just a test 
	 */
	public static void main(String[] args)
			{
			Operon operon=null;
			SnpIdsDB db=null;
			SnpIdsDB.KeyValueIterator iter=null;
			try {
				operon= Operon.newInstance();
				db= new SnpIdsDB(operon);
				if(!db.exists())return;
				db.open();
				
				System.err.println(db.get("rs25"));
				
				int n=0;
				for( iter=db.listKeyValues("rs251","rs252",true);
					iter.hasNext();
					)
					{
					Pair<String,SnpIds> p= iter.next();
					SnpIds value= p.second();
					System.err.println(p.first()+"\t"+value.getFid());
					if(n++>100) break;
					}
				
				}
			catch (Exception e)
				{
				e.printStackTrace();
				}
			finally
				{
				if(iter!=null) iter.close();
				if(db!=null) db.safeClose();
				if(operon!=null) operon.safeClose();
				}
			}
	
}
